package org.tokaf.normalizer;

import org.tokaf.TopKElement;
import org.tokaf.normalizer.ordering.AscendingOrdering;
import org.tokaf.normalizer.ordering.Ordering;

/**
 * <p> SimpleDividingNormalizer gets the number and divides it with given
 * divider.</p> <p>Copyright (c) 2006</p>
 * @author Alan Eckhardt
 * @version 1.0
 */
public class SimpleDividingNormalizer implements Normalizer {
	Ordering desc;

	String userName;

	double divider;

	public SimpleDividingNormalizer(Ordering desc, String userName,
			double divider) {
		this.desc = desc;
		this.userName = userName;
		this.divider = divider;
	}

	public SimpleDividingNormalizer(Ordering desc, double divider) {
		this.desc = desc;
		this.divider = divider;
	}

	public SimpleDividingNormalizer(double divider) {
		this.desc = new AscendingOrdering();
		this.divider = divider;
	}

	public double Normalize(Object o) {
		if (o == null)
			return 0;

		String s = o.toString();
		return desc.order(Double.parseDouble(s) / divider);
	}

	public double Normalize(TopKElement te, int index) {
		if (te == null)
			return 0;
		return Normalize(te.getRatingObject(index));
	}

	public boolean equals(Object obj) {
		return false;
	}

	public int compare(Object o1, Object o2) {
		double a = Normalize(o1);
		double b = Normalize(o2);
		if (a < b)
			return 1;
		if (a > b)
			return -1;
		return 0;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public Ordering getOrdering() {
		return desc;
	}

	public void setOrdering(Ordering desc) {
		this.desc = desc;
	}

	public double getDivider() {
		return divider;
	}

	public void setDivider(double divider) {
		this.divider = divider;
	}
}
